/* Start.s 
 *	Assembly language assist for user programs running on top of Nachos.
 *
 *	Since we don't want to pull in the entire C library, we define
 *	what we need for a user program here, namely Start and the system
 *	calls.
 */

#define IN_ASM
#include "syscall.h"

        .text   
        .align  2

/* -------------------------------------------------------------
 * __start
 *	Initialize running a C program, by calling "main". 
 *
 * 	NOTE: This has to be first, so that it gets loaded at location 0.
 *	The Nachos kernel always starts a program by jumping to location 0.
 * -------------------------------------------------------------
 */

	.globl __start
	.ent	__start
__start:
	jal	main
	move	$4,$0		
	jal	Exit	 /* if we return from main, exit(0) */
	.end __start

/* -------------------------------------------------------------
 * System call stubs:
 *	Assembly language assist to make system calls to the Nachos kernel.
 *	There is one stub per system call, that places the code for the
 *	system call into register r2, and leaves the arguments to the
 *	system call alone (in other words, arg1 is in r4, arg2 is 
 *	in r5, arg3 is in r6, arg4 is in r7)
 *
 * 	The return value is in r2. This follows the standard C calling
 * 	convention on the MIPS.
 * -------------------------------------------------------------
 */

	.globl Halt
	.ent	Halt
Halt:
	addiu $2,$0,SC_Halt
	syscall
	j	$31
	.end Halt

	.globl Exit
	.ent	Exit
Exit:
	addiu $2,$0,SC_Exit
	syscall
	j	$31
	.end Exit

	.globl Exec
	.ent	Exec
Exec:
	addiu $2,$0,SC_Exec
	syscall
	j	$31
	.end Exec

	.globl Join
	.ent	Join
Join:
	addiu $2,$0,SC_Join
	syscall
	j	$31
	.end Join

	.globl Create
	.ent	Create
Create:
	addiu $2,$0,SC_Create
	syscall
	j	$31
	.end Create

	.globl Open
	.ent	Open
Open:
	addiu $2,$0,SC_Open
	syscall
	j	$31
	.end Open

	.globl Read
	.ent	Read
Read:
	addiu $2,$0,SC_Read
	syscall
	j	$31
	.end Read

	.globl Write
	.ent	Write
Write:
	addiu $2,$0,SC_Write
	syscall
	j	$31
	.end Write

	.globl Close
	.ent	Close
Close:
	addiu $2,$0,SC_Close
	syscall
	j	$31
	.end Close

	.globl Fork
	.ent	Fork
Fork:
	addiu $2,$0,SC_Fork
	syscall
	j	$31
	.end Fork

	.globl Yield
	.ent	Yield
Yield:
	addiu $2,$0,SC_Yield
	syscall
	j	$31
	.end Yield

	
	
	.globl CreateLock
	.ent	CreateLock
CreateLock:
	addiu $2,$0,SC_CreateLock
	syscall
	j	$31
	.end CreateLock
	
	.globl DestroyLock
	.ent	DestroyLock
DestroyLock:
	addiu $2,$0,SC_DestroyLock
	syscall
	j	$31
	.end DestroyLock
	
	.globl AcquireLock
	.ent	AcquireLock
AcquireLock:
	addiu $2,$0,SC_AcquireLock
	syscall
	j	$31
	.end AcquireLock
	
	.globl ReleaseLock
	.ent	ReleaseLock
ReleaseLock:
	addiu $2,$0,SC_ReleaseLock
	syscall
	j	$31
	.end ReleaseLock	

	.globl CreateCondition
	.ent	CreateCondition
CreateCondition:
	addiu $2,$0,SC_CreateCondition
	syscall
	j	$31
	.end CreateCondition		

	.globl DestroyCondition
	.ent	DestroyCondition
DestroyCondition:
	addiu $2,$0,SC_DestroyCondition
	syscall
	j	$31
	.end DestroyCondition		

	.globl WaitCV
	.ent	WaitCV
WaitCV:
	addiu $2,$0,SC_WaitCV
	syscall
	j	$31
	.end WaitCV		

	.globl SignalCV
	.ent	SignalCV
SignalCV:
	addiu $2,$0,SC_SignalCV
	syscall
	j	$31
	.end SignalCV		

	.globl BroadcastCV
	.ent	BroadcastCV
BroadcastCV:
	addiu $2,$0,SC_BroadcastCV
	syscall
	j	$31
	.end BroadcastCV	

	.globl Rand
	.ent	Rand
Rand:
	addiu $2,$0,SC_Rand
	syscall
	j	$31
	.end Rand
	
	.globl InputInt
	.ent	InputInt
InputInt:
	addiu $2,$0,SC_InputInt
	syscall
	j	$31
	.end InputInt
	

	.globl rpcCreateLock
	.ent	rpcCreateLock
rpcCreateLock:
	addiu $2,$0,SC_rpcCreateLock
	syscall
	j	$31
	.end rpcCreateLock
	
	.globl rpcDestroyLock
	.ent	rpcDestroyLock
rpcDestroyLock:
	addiu $2,$0,SC_rpcDestroyLock
	syscall
	j	$31
	.end rpcDestroyLock

	.globl rpcAcquireLock
	.ent	rpcAcquireLock
rpcAcquireLock:
	addiu $2,$0,SC_rpcAcquireLock
	syscall
	j	$31
	.end rpcAcquireLock

	.globl rpcReleaseLock
	.ent	rpcReleaseLock
rpcReleaseLock:
	addiu $2,$0,SC_rpcReleaseLock
	syscall
	j	$31
	.end rpcReleaseLock	

	.globl rpcCreateCondition
	.ent	rpcCreateCondition
rpcCreateCondition:
	addiu $2,$0,SC_rpcCreateCondition
	syscall
	j	$31
	.end rpcCreateCondition
	
	.globl rpcDestroyCondition
	.ent	rpcDestroyCondition
rpcDestroyCondition:
	addiu $2,$0,SC_rpcDestroyCondition
	syscall
	j	$31
	.end rpcDestroyCondition
	
	.globl rpcWaitCV
	.ent	rpcWaitCV
rpcWaitCV:
	addiu $2,$0,SC_rpcWaitCV
	syscall
	j	$31
	.end rpcWaitCV	

	.globl rpcSignalCV
	.ent	rpcSignalCV
rpcSignalCV:
	addiu $2,$0,SC_rpcSignalCV
	syscall
	j	$31
	.end rpcSignalCV	

	.globl rpcBroadcastCV
	.ent	rpcBroadcastCV
rpcBroadcastCV:
	addiu $2,$0,SC_rpcBroadcastCV
	syscall
	j	$31
	.end rpcBroadcastCV
	
	.globl rpcCreateMV
	.ent	rpcCreateMV
rpcCreateMV:
	addiu $2,$0,SC_rpcCreateMV
	syscall
	j	$31
	.end rpcCreateMV
	
	.globl rpcDestroyMV
	.ent	rpcDestroyMV
rpcDestroyMV:
	addiu $2,$0,SC_rpcDestroyMV
	syscall
	j	$31
	.end rpcDestroyMV	

	.globl rpcGetValueMV 
	.ent	rpcGetValueMV 
rpcGetValueMV :
	addiu $2,$0,SC_rpcGetValueMV 
	syscall
	j	$31
	.end rpcGetValueMV 	

	.globl rpcSetValueMV 
	.ent	rpcSetValueMV 
rpcSetValueMV :
	addiu $2,$0,SC_rpcSetValueMV 
	syscall
	j	$31
	.end rpcSetValueMV 	


	
/* dummy function to keep gcc happy */
        .globl  __main
        .ent    __main
__main:
        j       $31
        .end    __main


		